package org.dbwebx.flex.control.renderer
{

	import mx.containers.HBox;
	import mx.core.ScrollPolicy;
	import org.dbwebx.domain.Bundle;
	import org.dbwebx.domain.SourceNode;
	import org.dbwebx.flex.control.DateLabel;

	public class DateGridRenderer extends HBox
	{

		public function DateGridRenderer()
		{
			super();
			horizontalScrollPolicy=ScrollPolicy.OFF;
			percentWidth=100;
		}

		/**
		 * The label.
		 * @default
		 */
		protected var labelField:DateLabel;

		override public function set data(value:Object):void
		{
			super.data=value;
			invalidateSize();
			invalidateDisplayList();
		}

		override protected function commitProperties():void
		{
			super.commitProperties();
			if (data)
			{
				if (data is Bundle)
				{
					renderDate(Bundle(data).updatedOn);
				}
				if (data is SourceNode)
				{
					renderDate(SourceNode(data).updatedOn);
				}
			}
		}

		override protected function createChildren():void
		{
			super.createChildren();
			labelField=new DateLabel();
			addChild(labelField);
		}

		private function renderDate(value:Date):void
		{
			if (value)
			{
				labelField.data=value;
			}
		}

	}
}